import { reqcartList ,reqremcartList,reqchecked} from '@/api'

// search 模块的小仓库
const state = {
    dataList: []
}
const mutations = {
    GETCARTLIST(state, rel) {
        state.dataList = rel
    }
}
const actions = {
    // 获取购物车数据
    async discartlist({ commit }) {
        let result = await reqcartList()
        if (result.code == 200) {
            commit('GETCARTLIST', result.data[0].cartInfoList)
        }
    },
    // 删除购物车数据
    async disremcartlist({commit},skuId){
        let result = await reqremcartList(skuId)
        if(result.code == 200) {
            // commit('REMCARTLIST', result.data)
        }
    },
    // 修改某一个购物车的checked状态
    async disreqchecked({commit},{skuId,isChecked}){
        let result = await reqchecked(skuId,isChecked)
        if(result.code == 200){
            return "ok"
        }else{
            Promise.reject(new Error("修改失败"))
        }
    }
}
const getters = {
    getcartList(){
        return state.dataList
    }
}
export default {
    state,
    mutations,
    actions,
    getters
}